{extend name="base" /}

{block name="content"}
<form class="layui-form" action="" id="searchBox">
    <div class="layui-inline">
        <div class="layui-input-inline">
            {MyTag:game type='channel' /}
        </div>
    </div>
    <div class="layui-inline">
        <a href="javascript:;" class="layui-btn searchBtn my-btn my-btn-sm">搜索</a>
    </div>
</form>

<table id="tableBox" lay-filter="tableBox"></table>

<script type="text/html" id="tableBar">
    <a href="{{ d.url }}" class="layui-btn layui-btn-green layui-btn-sm">下载</a>
</script>
{/block}

{block name="css"}
{/block}

{block name="js"}
<script>
    layui.use(['table', 'layer'], function(){
        var table = layui.table
            ,$ = layui.$
            ,form = layui.form
            ,layer = layui.layer
            ,load = layer.load()
            ,active = {
                reload: function () {
                    var game_id = $('#game_id').val();

                    table.reload('tableId', {
                        page: {curr: 1}
                        ,where: {game_id:game_id}
                        ,height: 'full-80'
                    })
                },
            };

        //表格初始化
        table.render({
            elem: '#tableBox'
            ,height: 'full-80'
            ,url: '{:url("GameMaterial/index")}'
            ,page: true
            ,limit:20
            ,limits:[20,40,60,80]
            ,loading:true
            ,id:'tableId'
            ,done: function () {
                layer.close(load);
            }
            ,cols: [[
                {field:'game_id', title: '游戏ID', width: 200}
                ,{field:'game_name', title: '游戏名称', width: 200}
                ,{field:'url', title: '下载地址'}
                ,{title: '操作', align:'center', width: 400, toolbar:'#tableBar'}
            ]]
        });

        $('#searchBox .searchBtn').on('click', function(){
            load = layer.load();
            active['reload'].call(this);
            return false;
        });
    });
</script>
{/block}